﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.DialogUI {
    import flash.events.*;
    import Engine.Managers.*;
    import flash.display.*;
    import flash.utils.*;
    import org.aswing.*;
    import Classes.*;
    import flash.filters.*;
    import org.aswing.geom.*;
    import Display.*;
    import flash.text.*;
    import org.aswing.event.*;
    import org.aswing.border.*;
    import Display.aswingui.*;
    import Modules.stats.types.*;
    import L10n.*;

    public class DailyBonusDialogView extends GenericDialogView {

        protected var m_bonusDay:int;
        protected var m_prevBonusDay:int;
        protected var m_bonusesInfoArray:Array;
        private var m_differenceAmount:int;
        protected var m_bonusArray:Array;
        protected var m_checkMark:CheckBox;
        protected var m_bCheckBox:Boolean = false;
        protected var m_rewardPane:AssetPane;
        protected var m_loader:Loader;
        protected var m_isBonusAvailable:Boolean;
        protected var m_isRecoveryNeeded:Boolean;

        public function DailyBonusDialogView(_arg1:Dictionary, _arg2:Boolean, _arg3:Boolean, _arg4:String="", _arg5:String="", _arg6:int=0, _arg7:Function=null, _arg8:String=""){
            this.m_isBonusAvailable = _arg2;
            this.m_isRecoveryNeeded = _arg3;
            super(_arg1, _arg4, _arg5, _arg6, _arg7, _arg8);
        }
        override protected function createHeaderPanel():JPanel{
            var _local1:JPanel = new JPanel(new BorderLayout());
            var _local2:JPanel = createCloseButtonPanel();
            var _local3:JPanel = createTitlePanel();
            ASwingHelper.prepare(_local2);
            ASwingHelper.setEasyBorder(_local3, 5);
            _local1.append(ASwingHelper.horizontalStrut(_local2.getWidth()), BorderLayout.WEST);
            _local1.append(_local3, BorderLayout.CENTER);
            _local1.append(_local2, BorderLayout.EAST);
            return (_local1);
        }
        override protected function init():void{
            if (m_type == TYPE_OK){
                m_acceptTextName = ZLoc.t("Dialogs", "OkButton");
            } else {
                if (m_type == TYPE_YESNO){
                    m_acceptTextName = ZLoc.t("Dialogs", "Yes");
                    m_cancelTextName = ZLoc.t("Dialogs", "No");
                } else {
                    if (m_type == TYPE_ACCEPTCANCEL){
                        m_acceptTextName = ZLoc.t("Dialogs", "Accept");
                        m_cancelTextName = ZLoc.t("Dialogs", "Cancel");
                    } else {
                        if (m_type == TYPE_SHARECANCEL){
                            m_acceptTextName = ZLoc.t("Dialogs", "Share");
                            m_cancelTextName = ZLoc.t("Dialogs", "Cancel");
                        } else {
                            if (m_type == TYPE_SENDGIFTS){
                                m_acceptTextName = ZLoc.t("Dialogs", "SendGifts");
                                m_cancelTextName = ZLoc.t("Dialogs", "Skip");
                            } else {
                                if (m_type == TYPE_CONFIRM){
                                    m_acceptTextName = ZLoc.t("Dialogs", "Confirm");
                                };
                            };
                        };
                    };
                };
            };
            m_bgAsset = (new (m_assetDict["dailyBonus_bg"])() as DisplayObject);
            this.makeBackground();
            makeCenterPanel();
            ASwingHelper.prepare(this);
        }
        override protected function createInteriorHolder():JPanel{
            var _local1:JPanel = new JPanel(new SoftBoxLayout(SoftBoxLayout.Y_AXIS, -10, SoftBoxLayout.TOP));
            _local1.setPreferredWidth(m_bgAsset.width);
            _local1.setMinimumWidth(m_bgAsset.width);
            _local1.setMaximumWidth(m_bgAsset.width);
            var _local2:JPanel = this.createHeaderPanel();
            ASwingHelper.prepare(_local2);
            this.m_bonusDay = (Global.player.dailyBonusManager.currentBonusDay - 1);
            this.m_prevBonusDay = (Global.player.dailyBonusManager.previousBonusDay - 1);
            this.m_differenceAmount = (this.m_bonusDay - this.m_prevBonusDay);
            this.m_bonusArray = Global.player.dailyBonusManager.getDailyBonusRange(1, 5);
            textArea = this.createTextArea();
            ASwingHelper.prepare(textArea);
            _local1.setBorder(new EmptyBorder(null, new Insets(0, 0, 0, 0)));
            _local1.append(_local2);
            _local1.append(ASwingHelper.verticalStrut(20));
            _local1.append(textArea);
            _local1.append(ASwingHelper.verticalStrut(10));
            return (_local1);
        }
        private function determineDailyRewardType(_arg1:int):String{
            var _local2:String;
            if (this.m_bonusArray[_arg1].goods > 0){
                _local2 = "goods";
            } else {
                if (this.m_bonusArray[_arg1].energy > 0){
                    _local2 = "energy";
                } else {
                    if (this.m_bonusArray[_arg1].xp > 0){
                        _local2 = "xp";
                    } else {
                        if (this.m_bonusArray[_arg1].coin > 0){
                            _local2 = "coin";
                        };
                    };
                };
            };
            return (_local2);
        }
        private function determineDailyRewardAmount(_arg1:int):Number{
            var _local2:Number;
            if (this.m_bonusArray[_arg1].goods > 0){
                _local2 = this.m_bonusArray[_arg1].goods;
            } else {
                if (this.m_bonusArray[_arg1].energy > 0){
                    _local2 = this.m_bonusArray[_arg1].energy;
                } else {
                    if (this.m_bonusArray[_arg1].xp > 0){
                        _local2 = this.m_bonusArray[_arg1].xp;
                    } else {
                        if (this.m_bonusArray[_arg1].coin > 0){
                            _local2 = this.m_bonusArray[_arg1].coin;
                        };
                    };
                };
            };
            return (_local2);
        }
        override protected function makeBackground():void{
            if (m_bgAsset){
                ASwingHelper.setSizedBackground(this, m_bgAsset, new Insets(0, 0, 10));
            };
        }
        private function createDailyHolders():JPanel{
            var _local4:Object;
            var _local5:Object;
            var _local6:DisplayObject;
            var _local7:String;
            var _local8:uint;
            var _local9:String;
            var _local10:DisplayObject;
            var _local11:Boolean;
            var _local12:AssetPane;
            var _local13:JPanel;
            var _local14:JPanel;
            var _local15:JPanel;
            var _local16:JPanel;
            var _local17:JTextField;
            var _local18:JPanel;
            var _local19:Number;
            var _local20:JPanel;
            var _local21:DisplayObject;
            var _local22:JTextField;
            var _local23:String;
            var _local24:Number;
            var _local25:JPanel;
            var _local26:JLabel;
            var _local27:Array;
            var _local28:Array;
            var _local29:String;
            var _local30:ScrollingImageObject;
            var _local31:String;
            var _local32:Sprite;
            var _local33:Number;
            var _local34:JLabel;
            var _local35:JPanel;
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT, -15);
            this.m_bonusesInfoArray = new Array();
            var _local2:int;
            while (_local2 < 5) {
                _local4 = new Object();
                if (((this.m_isBonusAvailable) && (!(this.m_isRecoveryNeeded)))){
                    if (_local2 < this.m_bonusDay){
                        _local4.success = "green";
                    } else {
                        if (_local2 == this.m_bonusDay){
                            _local4.success = "green_selected";
                        } else {
                            _local4.success = "regular";
                        };
                    };
                } else {
                    if (_local2 <= this.m_prevBonusDay){
                        _local4.success = "green";
                    } else {
                        if ((((_local2 > this.m_prevBonusDay)) && ((_local2 < this.m_bonusDay)))){
                            _local4.success = "red";
                        } else {
                            if (_local2 == this.m_bonusDay){
                                _local4.success = "red_selected";
                            } else {
                                _local4.success = "regular";
                            };
                        };
                    };
                };
                this.m_bonusesInfoArray.push(_local4);
                _local2++;
            };
            var _local3:int;
            while (_local3 < 5) {
                _local5 = this.m_bonusesInfoArray[_local3];
                if (_local3 == 0){
                    _local7 = ("dailyBonus_tab_left_" + _local5.success);
                    _local6 = (new (m_assetDict[_local7])() as DisplayObject);
                } else {
                    if (_local3 == 4){
                        _local7 = ("dailyBonus_tab_right_" + _local5.success);
                        _local6 = (new (m_assetDict[_local7])() as DisplayObject);
                    } else {
                        _local7 = ("dailyBonus_tab_mid_" + _local5.success);
                        _local6 = (new (m_assetDict[_local7])() as DisplayObject);
                    };
                };
                _local9 = this.determineDailyRewardType(_local3);
                _local11 = true;
                _local12 = new AssetPane();
                _local13 = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
                if ((((_local5.success == "green")) || ((_local5.success == "green_selected")))){
                    _local8 = EmbeddedArt.greenTextColor;
                    _local10 = (new (m_assetDict["dailyBonus_check"])() as DisplayObject);
                } else {
                    if ((((_local5.success == "red")) || ((_local5.success == "red_selected")))){
                        _local8 = EmbeddedArt.redTextColor;
                        _local10 = (new (m_assetDict["dailyBonus_x"])() as DisplayObject);
                    } else {
                        _local8 = EmbeddedArt.blueTextColor;
                        if (_local3 != 4){
                            _local23 = ("doober_" + _local9);
                            _local10 = (new (m_assetDict[_local23])() as DisplayObject);
                            ASwingHelper.setEasyBorder(_local12, 15);
                            _local24 = this.determineDailyRewardAmount(_local3);
                            _local25 = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
                            _local26 = ASwingHelper.makeLabel(String(_local24), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, EmbeddedArt.blueTextColor);
                            _local25.append(_local26);
                        } else {
                            _local10 = null;
                            _local27 = new Array();
                            _local28 = (this.m_bonusArray[4] as DailyBonus).items;
                            for each (_local29 in _local28) {
                                _local31 = Global.gameSettings.getImageByName(_local29, "icon");
                                _local27.push(_local31);
                            };
                            _local27.reverse();
                            _local27.push(Global.getAssetURL("assets/doobers/bolt_doober.png"));
                            _local30 = new ScrollingImageObject(_local27, 75, 75, "assets/dialogs/questionMark.png");
                            _local11 = false;
                        };
                    };
                };
                _local14 = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.BOTTOM);
                _local15 = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP);
                _local16 = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP, -3);
                ASwingHelper.setEasyBorder(_local16, 5, 0);
                if (_local5.success != (("red_selected") || ("green_selected"))){
                    ASwingHelper.setSizedBackground(_local15, _local6);
                } else {
                    ASwingHelper.setSizedBackground(_local15, _local6);
                };
                _local18 = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
                _local19 = TextFieldUtil.getLocaleFontSize(16, 14, [{
                    locale:"it",
                    size:12
                }, {
                    locale:"fr",
                    size:12
                }, {
                    locale:"de",
                    size:16
                }, {
                    locale:"es",
                    size:16
                }]);
                _local17 = ASwingHelper.makeTextField(ZLoc.t("Dialogs", "DayNumber", {amount:(_local3 + 1)}), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, _local19, _local8);
                _local18.append(_local17);
                _local12.setAsset(_local10);
                if (_local3 != 4){
                    _local13.append(_local12);
                } else {
                    if (_local30){
                        _local32 = new Sprite();
                        _local32.graphics.beginFill(0);
                        _local32.graphics.lineTo(120, 0);
                        _local32.graphics.lineTo(120, 60);
                        _local32.graphics.curveTo(120, 78, 100, 78);
                        _local32.graphics.lineTo(5, 78);
                        _local32.graphics.lineTo(24, 32);
                        _local32.graphics.lineTo(21, 0);
                        _local32.graphics.endFill();
                        _local13.addChild(_local32);
                        _local30.mask = _local32;
                        _local13.addChild(_local30);
                        _local30.x = 30;
                        _local30.y = 3;
                        _local13.setPreferredSize(new IntDimension(50, 100));
                    } else {
                        _local13.append(_local12);
                    };
                };
                if (_local3 != 4){
                    _local16.appendAll(_local18, _local13, _local25);
                } else {
                    _local16.appendAll(_local18, _local13);
                };
                if ((((_local3 == 4)) && (!((_local3 == this.m_bonusDay))))){
                    _local33 = TextFieldUtil.getLocaleFontSize(12, 11, [{
                        locale:"de",
                        size:10
                    }, {
                        locale:"es",
                        size:9
                    }]);
                    _local34 = ASwingHelper.makeLabel(ZLoc.t("Dialogs", "ChanceToWin"), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, _local33, EmbeddedArt.blueTextColor);
                    _local35 = ASwingHelper.centerElement(_local34);
                    _local16.remove(_local25);
                    _local16.insert(1, _local35);
                };
                if (_local3 == 0){
                };
                _local15.append(_local16);
                _local14.append(_local15);
                _local1.append(_local14);
                _local3++;
            };
            return (_local1);
        }
        private function todaysGiftItemType(_arg1:int):String{
            var _local2:String;
            if (this.m_bonusArray[_arg1].goods > 0){
                _local2 = ZLoc.t("Dialogs", "TodaysWinGoods");
            } else {
                if (this.m_bonusArray[_arg1].energy > 0){
                    _local2 = ZLoc.t("Dialogs", "TodaysWinEnergy");
                } else {
                    if (this.m_bonusArray[_arg1].xp > 0){
                        _local2 = ZLoc.t("Dialogs", "TodaysWinXP");
                    } else {
                        if (this.m_bonusArray[_arg1].coin > 0){
                            _local2 = ZLoc.t("Dialogs", "TodaysWinCoins");
                        };
                    };
                };
            };
            return (_local2);
        }
        override protected function createTextArea():JPanel{
            var titleString:* = null;
            var awardText:* = null;
            var shareText:* = null;
            var prizeObject:* = null;
            var prizePane:* = null;
            var shareBtn:* = null;
            var prizeItem:* = null;
            var prizeLoader:* = null;
            var index:* = null;
            var index2:* = null;
            var cashIcon:* = null;
            var prizeIndex:* = null;
            var textArea:* = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER, 10);
            var textInnerArea:* = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var shareBtnHolder:* = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER, 10);
            prizePane = new AssetPane();
            if (((this.m_isBonusAvailable) && (!(this.m_isRecoveryNeeded)))){
                titleString = ZLoc.t("Dialogs", "BetterBonuses");
                awardText = ((ZLoc.t("Dialogs", "TodaysWin", {amount:String(this.determineDailyRewardAmount(this.m_bonusDay))}) + " ") + this.todaysGiftItemType(this.m_bonusDay));
                shareText = ZLoc.t("Dialogs", "ExtraShare");
                shareBtn = new CustomButton(ZLoc.t("Dialogs", "Share"), null, "GreenButtonUI");
                shareBtnHolder.append(shareBtn);
                shareBtn.addActionListener(this.shareThis, 0, true);
                if (this.m_bonusDay == (Global.gameSettings.getDailyBonusMaxStreak() - 1)){
                    if (Global.player.dailyBonusManager.randomReward){
                        prizeItem = Global.gameSettings.getItemByName(Global.player.dailyBonusManager.randomReward);
                        awardText = ZLoc.t("Dialogs", "TodaysWin", {amount:prizeItem.localizedName});
                        prizeObject = null;
                        prizeLoader = LoadingManager.load(prizeItem.icon, function ():void{
                            prizePane.setAsset(prizeLoader.content);
                        });
                    } else {
                        index = ("doober_" + this.determineDailyRewardType(this.m_bonusDay));
                        prizeObject = (new (m_assetDict[index])() as DisplayObject);
                    };
                } else {
                    index2 = ("doober_" + this.determineDailyRewardType(this.m_bonusDay));
                    prizeObject = (new (m_assetDict[index2])() as DisplayObject);
                };
            } else {
                titleString = ZLoc.t("Dialogs", "MissedDay");
                awardText = ZLoc.t("Dialogs", "MissingLoss", {amount:this.m_bonusArray[this.m_bonusDay].coin});
                shareText = ZLoc.t("Dialogs", "RecoverOption");
                cashIcon = new AssetIcon((new EmbeddedArt.icon_cash() as DisplayObject));
                if (this.m_bonusDay == (Global.gameSettings.getDailyBonusMaxStreak() - 1)){
                    awardText = ZLoc.t("Dialogs", "MissingGiftLoss");
                    prizeObject = (new (m_assetDict["dailyBonus_present_big"])() as DisplayObject);
                } else {
                    prizeIndex = ("doober_" + this.determineDailyRewardType(this.m_bonusDay));
                    prizeObject = (new (m_assetDict[prizeIndex])() as DisplayObject);
                };
            };
            var titleHolder:* = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var titleText:* = ASwingHelper.makeTextField(titleString, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 22, 4627661);
            titleHolder.append(titleText);
            var hrHolder:* = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER);
            var hrObject:* = (new (m_assetDict["dailyBonus_hr"])() as DisplayObject);
            var hrPane:* = new AssetPane(hrObject);
            hrHolder.append(hrPane);
            var prizeHolder:* = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.CENTER, 10);
            prizePane.setAsset(prizeObject);
            var prizeMessageHolder:* = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.TOP, 5);
            var prizeText:* = ASwingHelper.makeTextField(awardText, EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 22, EmbeddedArt.brownTextColor);
            var subprizeText:* = ASwingHelper.makeTextField((shareText + "      "), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 14, EmbeddedArt.brownTextColor);
            prizeMessageHolder.appendAll(prizeText, subprizeText, shareBtnHolder);
            prizeHolder.appendAll(prizePane, prizeMessageHolder);
            var dailysHolder:* = this.createDailyHolders();
            var todayHolder:* = this.createTodayHolder();
            textInnerArea.appendAll(ASwingHelper.verticalStrut(7), titleHolder, ASwingHelper.verticalStrut(5), hrHolder, ASwingHelper.verticalStrut(5), prizeHolder, ASwingHelper.verticalStrut(13), dailysHolder, todayHolder);
            textArea.append(textInnerArea);
            return (textArea);
        }
        private function createTodayHolder():JPanel{
            var _local1:JPanel = ASwingHelper.makeSoftBoxJPanel(SoftBoxLayout.LEFT, 25);
            _local1.setPreferredWidth(m_bgAsset.width);
            _local1.setMinimumWidth(m_bgAsset.width);
            _local1.setMaximumWidth(m_bgAsset.width);
            ASwingHelper.setEasyBorder(_local1, 0, 25);
            var _local2:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local3:DisplayObject = (new (m_assetDict["dailyBonus_tab"])() as DisplayObject);
            var _local4:TextFormat = new TextFormat();
            _local4.align = TextFormatAlign.CENTER;
            var _local5:Array = [new DropShadowFilter(1, 45, 0, 0.5, 0, 0, 5)];
            var _local6:JTextField = ASwingHelper.makeTextField(ZLoc.t("Dialogs", "Today"), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, 0xFFFFFF, 0, _local4);
            _local6.filters = _local5;
            var _local7:JPanel = ASwingHelper.centerElement(_local6);
            _local2.append(_local7);
            ASwingHelper.setSizedBackground(_local2, _local3);
            var _local8:JPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.CENTER);
            var _local9:DisplayObject = (new (m_assetDict["dailyBonus_tab"])() as DisplayObject);
            var _local10:JTextField = ASwingHelper.makeTextField(ZLoc.t("Dialogs", "Tomorrow"), EmbeddedArt.DEFAULT_FONT_NAME_BOLD, 12, 0xFFFFFF, 0, _local4);
            _local10.filters = _local5;
            var _local11:JPanel = ASwingHelper.centerElement(_local10);
            _local8.append(_local11);
            ASwingHelper.setSizedBackground(_local8, _local9);
            var _local12:Number = ((this.m_bonusDay * 115) - 35);
            if (_local12 > 0){
                _local1.append(ASwingHelper.horizontalStrut(_local12));
            };
            _local1.appendAll(_local2, _local8);
            return (_local1);
        }
        private function checkEmail(_arg1:MouseEvent):void{
            if (this.m_bCheckBox == true){
                this.m_bCheckBox = false;
                this.m_checkMark.turnOff();
            } else {
                this.m_bCheckBox = true;
                this.m_checkMark.turnOn();
            };
        }
        private function startOver(_arg1:AWEvent):void{
            this.onCancel(_arg1);
        }
        private function shareThis(_arg1:AWEvent):void{
            Global.world.viralMgr.sendDailyBonusFeed();
            this.onAccept(_arg1);
        }
        private function recoverStreak(_arg1:AWEvent):void{
            if (Global.player.dailyBonusManager.extraCashNeededForRecovery > 0){
                this.onCancel(_arg1);
                if (LocaleHelper.localSetting.sns.cash_enable){
                    UI.displayPopup(new GetCoinsDialog(ZLoc.t("Dialogs", "ImpulseMarketCash"), "", GenericDialogView.TYPE_YESNO, null, true));
                    StatsManager.sample(100, StatsCounterType.HUD_COUNTER, "add_currency");
                };
            } else {
                Global.player.dailyBonusManager.collectDailyBonus();
                this.onAccept(_arg1);
            };
        }

    }
}//package Display.DialogUI 
